package org.lds.hotkey.client.autoconfigure.hotkey.receive;

import lombok.extern.slf4j.Slf4j;
import org.lds.hotkey.client.cache.HotKeyCache;
import org.lds.hotkey.common.model.dto.ResultDTO;
import org.lds.hotkey.console.remote.model.BatchReceiveHotkeyRequest;
import org.springframework.web.bind.annotation.RequestBody;

@Slf4j
public class ReceiveHotKeyService {
    public ResultDTO receiveHotkey(@RequestBody BatchReceiveHotkeyRequest request) {
        log.info("感知到热key data={}", request);
        request.getRequests().forEach(receiveHotkeyRequest -> HotKeyCache.put(receiveHotkeyRequest.getDuration(), receiveHotkeyRequest.getKey(), receiveHotkeyRequest.getRuleId()));
        return ResultDTO.success();
    }
}
